<template>
	<div id="goods_refund_confirm" class="container">
		<div class="title">
			退费
			<div class="close" @click="close()"></div>
		</div>
		
		<div class="info">
			<div>学员姓名：{{student.realName}}</div>
			<div>联系人：{{student.parentName}}</div>
			<div>联系电话：{{student.phone}}</div>
		</div>
		
		<div class="content">
			<div class="table">
				<div class="thead">
					<div style="width: 1.8rem;">名称</div>
					<div style="width: 1.2rem;">分类</div>
					<div style="width: 1.2rem;">单价</div>
					<div style="width: 1.2rem;">购买数量</div>
					<div style="width: 1.2rem;">总价</div>
					<div style="width: 1.2rem;">实际支付</div>
					<div style="width: 1.2rem;">应退数量</div>
					<div style="width: 1.2rem;">应退费</div>
				</div>
				<div class="tbody">
					<div class="tr_div" v-for="item,index in countList">
						<div class="tr">
							<div style="width: 1.8rem;">{{item.goodsName}}</div>
							<div style="width: 1.2rem;">{{item.goodsMode}}</div>
							<div style="width: 1.2rem;">￥{{item.salesPrice}}</div>
							<div style="width: 1.2rem;">{{item.goodsNum}}</div>
							<div style="width: 1.2rem;">￥{{item.totalMoney}}</div>
							<div style="width: 1.2rem;">￥{{item.realMoney}}</div>
							<div style="width: 1.2rem;">{{item.goodsNum}}</div>
							<div style="width: 1.2rem;">￥{{item.realMoney}}</div>
						</div>
					</div>
				</div>
			</div>

			<div class="count">
				<div class="real_money">
					应退费总计：
					<span>￥{{money}}</span>
				</div>
			</div>

			<div class="row">
				<label class="label_2">
					<span>*</span>实际退费：
				</label>
				￥<el-input v-model="param.realMoney" id="realMoney" type="text" style="width:1.7rem ;" maxLength = "10"
					onpaste="return false;" onkeypress="return(/[\d]/.test(String.fromCharCode(event.keyCode)))"></el-input>
			</div>
			
			<div class="row">
				<label class="label_2">
					<span>*</span>退款方式：
				</label>
				<div class="radio_group">
					<label class="radio" @click="param.payMode = 100">
						<span class="radio_circle" :class="param.payMode==100 ? 'radio_active' : ''"></span>
						<span class="radio_name">原路返回</span>
					</label>
					<label class="radio" v-for="(item, index) in payType" @click="param.payMode = item.value">
						<span class="radio_circle" :class="item.value == param.payMode ? 'radio_active' : ''"></span>
						<span class="radio_name">{{ item.name }}</span>
					</label>
				</div>
			</div>

			<div class="row">
				<label class="label_2" style="width: 1.17rem;letter-spacing: 0;">
					<span>*</span>收款人信息：
				</label>
				<el-input v-model="param.payeeName" id="payeeName" style="width:1.7rem;" placeholder="收款人姓名" maxLength="10"></el-input>
				&nbsp;
				<el-input v-model="param.payeeTel" id="payeeTel" style="width:2rem;" placeholder="收款人联系方式" maxLength="11"></el-input>
			</div>
			
		</div>
		<div class="btn_div">
			<div class="btn_sure" @click="ok()">确认退费</div>
			<div class="btn_cancel" @click="back()">上一步</div>
		</div>
	</div>
</template>

<script>
var vm, dict;
var param = {
	studentId : "",
	refundMode : "2",
	payeeName : "",
	payeeTel : "",
	payMode : "",
	realMoney : "",
	remark : "",
	orderRefundGoodsEntityList : []
}
export default {
	data: function() {
		return {
			student: {},
			countList: [],
			param: tool.clone(param),
			money : 0,
			//数据字典
			payType: null,
		};
	},
	methods: {
		init: function(student, countList) {
			//初始线索和结算列表数据
			vm.student = student;
			vm.countList = countList;
			
			//初始化参数值
			vm.param = tool.clone(param);
			
			vm.money = 0;
			countList.forEach(function(item) {
				vm.money += item.realMoney;
			});
			vm.money = parseFloat(vm.money.toFixed(2));
			
			vm.param.realMoney = vm.money;
			vm.param.studentId = student.studentId;
			vm.param.payeeName = student.parentName;
			vm.param.payeeTel = student.phone;
			vm.param.payMode = vm.payType[0].value;
		},
		//提交报名数据
		ok: function() {
			//验证规则
			var rules = [{
				judge: vm.param.realMoney,
				focus: $('#goods_refund_confirm #realMoney'),
				tips: '请输入实际退费'
			},{
				judge: vm.param.realMoney <= vm.money,
				focus: $('#goods_refund_confirm #realMoney'),
				tips: '实际退费不得大于应退费'
			},{
				judge: tool.judge("name", vm.param.payeeName),
				focus: $('#goods_refund_confirm #payeeName'),
				tips: tips.name
			},{
				judge: tool.judge("phone", vm.param.payeeTel),
				focus: $('#goods_refund_confirm #payeeTel'),
				tips: tips.phone
			},];

			if (!tool.validate(rules)) {
				return;
			}

			var param = tool.clone(vm.param);

			//商品列表
			 vm.countList.forEach(function(item) {
			 	param.orderRefundGoodsEntityList.push({
					studentGoodsId: item.id,
					goodsNum: item.goodsNum,
				});
			 })
			 
			 //后台把字段名打错！！！
			 param.relMoney = param.realMoney;
			 delete param.realMoney;
			
			//退费
			api.refund(param).then(function(data) {
				param.money = vm.money;
				param.time = tool.DateToString(new Date(), "yyyy-MM-dd HH:mm:ss");
				vm.$emit('ok', vm.countList, param);
			});
		},
		close: function() {
			vm.$emit('close');
		},
		back: function() {
			vm.$emit('back');
		},
	},
	mounted: function() {},
	created: function() {
		vm = this;
		dict = tool.getItem(lsKey.dict, true);
		vm.payType = dict['pay_mode'];
		
		for(let i=0; i<vm.payType.length; i++) {
			let v = vm.payType[i].value;
			if(v == 3 || v==4) {
				vm.payType.splice(i,1);
				i--;
			}
		}
//		vm.payType.unshift({name: "原路返还", value : 100});
	}
};
</script>
<style scoped src="@/style/module/radio.css"></style>
<style scoped src="@/style/module/dialog.css"></style>
<style scoped src="@/style/module/table2.css"></style>
<style scoped>
.radio_group {
	color: #333333;
	font-size: 0.18rem;
	padding-left: 0.2rem;
	padding-bottom: 0.05rem;
}

.radio_circle {
	top: 0.01rem;
}

.tr > div,
.thead > div {
	width: 1.4rem;
}

.tr_two_row {
	padding-top: 0.05rem;
	line-height: 0.2rem;
}

.content {
	padding: 0 0.3rem;
}

/* ----------信息栏---------- */
.info {
	/*outline: 1px solid red;*/
	font-size: 0.16rem;
	color: #666666;
	overflow: hidden;
	padding: 0.1rem 0 0.15rem 0.4rem;
}
.info>div {
	float: left;
	width: 2.8rem;
}

.label {
	padding-right: 0.05rem;
	color: #666666;
}

.value {
	width: 1.9rem;
	height: 0.3rem;
	font-size: 0.16rem;
	color: #333333;
	letter-spacing: 0.01rem;
}

.type {
	margin-left: 0.1rem;
	display: inline-block;
	height: 0.2rem;
	line-height: 0.2rem;
	font-size: 0.12rem;
	background-color: #3885f8;
	color: white;
	border-radius: 0.05rem;
	padding: 0 0.05rem;
	margin-right: 0.03rem;
}

.count {
	padding: 0.1rem 0.1rem 0.1rem 0;
	/*margin-bottom: 0.05rem;*/
	text-align: right;
	line-height: 0.3rem;
	color: #333333;
	font-size: 0.18rem;
	border-bottom: 0.01rem solid #f3f6fc;
	overflow: hidden;
}

.count > div {
	float: right;
}

.reduce {
	font-size: 0.16rem;
	cursor: pointer;
}

.earnest {
	font-size: 0.16rem;
	cursor: pointer;
	/*margin-bottom: 0.08rem;*/
}

.earnest_check {
	display: inline-block;
	vertical-align: middle;
	width: 0.25rem;
	height: 0.25rem;
	background-size: 0.16rem;
	background-repeat: no-repeat;
	background-position: center;
	background-image: url(../../../assets/img/clue_manage/check_no.png);
	position: relative;
	bottom: 0.01rem;
}

.earnest_check_active {
	background-image: url(../../../assets/img/clue_manage/check_yes.png);
}

.real_money {
	padding-top: 0.08rem;
}

.real_money > span {
	font-size: 0.26rem;
	color: #fc7301;
}

.title_sub {
	font-size: 0.22rem;
	color: #333333;
	line-height: 0.6rem;
}

.title_sub span {
	display: inline-block;
	color: red;
	width: 0.2rem;
	position: relative;
	top: 0.02rem;
}

.row {
	padding-left: 0.1rem;
	margin-top: 0.15rem;
	font-size: 0.16rem;
	color: #666666;
}

.label_2 {
	display: inline-block;
	width: 1rem;
}

.label_2 > span {
	display: inline-block;
	color: red;
	width: 0.15rem;
	position: relative;
	top: 0.01rem;
}

.contract {
	margin-left: 0.1rem;
	display: inline-block;
	min-width: 0.75rem;
	padding-left: 0.22rem;
	font-size: 0.16rem;
	color: #666666;
	vertical-align: middle;
	background-size: 0.16rem;
	background-repeat: no-repeat;
	background-position: left center;
	background-image: url(../../../assets/img/clue_manage/check_no.png);
	cursor: pointer;
	user-select: none;
}

.contract_check {
	background-image: url(../../../assets/img/clue_manage/check_yes.png);
}
</style>
